1. Field of the Invention
The present invention relates to an information processor having a function of dynamically incorporating a behavior measuring procedure by rewriting instructions of a program to dynamically change structure of the program, and a method therefor.
2. Description of the Related Art
Debugger for use in detecting errors in computer programs is capable, during the execution of a predetermined computer program, of conducting operation of interrupting the execution to rewrite instructions of the computer program and change operation which is based on the computer program. With this function, execution of a computer program is interrupted at a place (break point) on the computer program designated by a programmer to shift control to the debugger, thereby allowing a programmer to input a debug command. One of conventional debuggers of this kind is recited, for example, in the ninth and the tenth chapters of the literature "Guidance to C Programming" (NEC UX Software Manual WTY 18-1) (hereinafter referred to as Literature 1).
The debugger recited in Literature 1 is the one for debugging an application program (AP program) running under control of an operating system (OS). The debugger is capable of operating as other process (referred to as a debugger process here) than a process in which an AP program runs (referred to as an AP process here) and is capable of accessing a memory in the AP process. For a programmer to set a break point in the AP process, he rewrites an instruction at a position at which the break point is to be set into an instruction to shift control to the debugger by making use of the function of accessing a memory in the AP process from the debugger process. As a result, when the execution of the AP program reaches the break point, the control shifts to the debugger process to wait for programmer's input of a debug command.
When the execution of the AP program reaches a break point, the debugger recited in the ninth chapter of Literature 1 is allowed to resume the execution of the AP program after sequentially executing combinations of commands (command group) prepared in the debugger. The command group is set at a break point in advance by a user. On the other hand, the debugger recited in the tenth chapter of Literature 1 is capable of executing a series of debugger commands written in a file at the start-up. It is therefore possible to set break points at a plurality of places at the time of start-up of the debugger. In any of the debuggers, instructions to be set at a break point are of a kind to shift control to the debugger. Also, the debuggers operate according to an executed break point. Operation for finding which break point has been executed is accordingly necessary.
In addition, in the debugger of Literature 1, execution of a break point in an AP program always results in shifting control to the debugger. An AP program in which a break point is set therefore can be executed only when the debugger operates, and terminates its operation when the debugger is finished.
With the debugger of Literature 1, executing operation designated at a break point is only a combination of debugger commands and none of arbitrary procedures can be executed.
A debugger for detecting errors in an operating system is also the same in its basic operation as a debugger intended for an AP program. For using the debugger of this kind, it is necessary to start a system with the debugger incorporated therein and run an operating system under control of this debugger.
Debuggers are thus used in a peculiar mode different from a normal operation mode (hereinafter referred to as a normal operation mode). This disables common users of information processors to use a debugger in most cases. Common users are therefore not allowed to conduct operation of dynamically changing the information processor from a normal operation mode to a special mode in which an arbitrary operation which was defined previously is executed just after when the execution reaches to a specific point in the operating system and then subsequent operation of the operating system will be executed (hereinafter referred to as a changed operation mode).
Another example of conventional debuggers is disclosed in Japanese Patent Laying-Open (Kokai) No. Heisei 1-274253, entitled "Software Break System" (hereinafter referred to as Literature 2). Recited in Literature 2 is a technique to have a break point setting means for rewriting machine words at break points into instructions to branch to break processing, a debugged program stopping means for, when debug processing is executed by a debugger, stopping execution of a debugged program, an execution means for executing debug processing, and a debugged program execution starting means for resuming execution of a debugged program after the completion of debug processing, thereby using a sub-routine branch instruction at a break point to branch from the debugged program to a routine in the debugger. According to this conventional art, however, since a program to be debugged in which break points are to be embedded needs to be placed under control of a debugger, a debugger is essential for rewriting instructions.
A further example of conventional debuggers is disclosed in Japanese Patent Laying Open (Kokai) No. Heisei 2-284236, entitled "Program Debug Processing Device" (hereinafter referred to as Literature 3). Recited in Literature 3 is a debug processing means for executing debug processing including a means for executing, as a dummy, a first instruction as a target of processing after execution of debug processing, a means for returning, to the first instruction, a first branch instruction to shift the first instruction to the debug processing, a means for embedding a second branch instruction to shift processing to the debug processing in a second instruction as a target of the debug processing to be conducted next, a means for setting an address at which the first instruction resides to a program counter, and a means for returning control to a debugged program. The conventional technique, however, is not effective as a means for modifying a program structure permanently because when the debugger is started by a break point, operation of restoring a saved instruction is conducted therein.
Still further example of conventional debuggers is disclosed in Japanese Patent Laying-Open (Kokai) No. Heisei 4-33135, entitled "Program Debugging System" (hereinafter referred to as Literature 4). Recited in Literature 4 is a technique of saving instructions of a main part of a program to be debugged and instead writing a procedure call-up instruction to call a debugger, starting the debugger by the procedure call-up instruction when the procedure call-up instruction is executed during the execution of the program to be debugged, and further, returning saved instructions to the original part by the debugger, thereby conducting debug processing.
Still further example of conventional debuggers is disclosed in Japanese Patent Laying-Open (Kokai) No. Heisei 5-241889, entitled "Machine Instruction Step Execution System" (hereinafter referred to as Literature 5). Recited in Literature 5 is a technique facilitating designation of interruption of step execution until a loop ends by taking, when a conditional branch instruction to conduct loop end control is given, an instruction at which a break point is to be set next as an instruction to which the branch instruction is to jump or the subsequent instruction, irrespective of whether branch conditions are satisfied or not.
Still further example of conventional debuggers is disclosed in Japanese Patent Laying Open (Kokai) No. Heisei 7-73032, entitled "Method of Dynamically Modifying Software System" (hereinafter referred to as Literature 6). Recited in Literature 6 is a technique of facilitating debug of ROM-based embedded software by inserting a customizable call-out request through ROM-based embedded software by means of an extensible interpreter.
Still further example of conventional debuggers is disclosed in Japanese Patent Laying-Open (Kokai) No. Heisei 8-255096, entitled "Microprocessor and Debug System" (hereinafter referred to as Literature 7). Recited in Literature 7 is a system including a processor core for executing a user program and a monitor program for debugging a user target system, and a debug module having an interface function for enabling the processor core to execute the monitor program and an execution control function for enabling the processor core, during the execution of the user program, to request an interruption to shift from the user program to the monitor program, thereby facilitating connection between the user target system and a debugger.
Still further example of conventional debuggers is disclosed in Japanese Patent Laying-Open (Kokai) No. Heisei 8-147155, entitled "Object Program Instruction Changing/Inserting Method and System Therefor" (hereinafter referred to as Literature 8). Recited in Literature 8 is a technique of once reversely assembling an object program whose instructions are to be changed or in which instructions are to be inserted to convert into a source program and after making predetermined changes, reassembling the program to generate an object program whose instructions have been changed or in which instructions have been inserted.
An example of conventional art of rewriting instructions in a program in order to dynamically change the structure of the program is disclosed in Japanese Patent Laying-Open (Kokai) No. Heisei 6-110678, entitled "Program Execution System and Execution Program Dynamically Changing Method" (hereinafter referred to as Literature 9). Recited in Literature 9 is a technique of correcting a bug of a former sub-routine to prepare a new sub-routine corresponding to the former sub-routine, and replacing a leading instruction of the former sub-routine by an instruction branching to the new sub-routine, thereby enabling an execution module including the former sub-routine to be replaced without stopping with an execution module including the new sub-routine. The technique of Literature 9, however, is intended to change an original instruction execution path to replace the entire sub-routine and is therefore impossible to insert an arbitrary procedure in the middle of the original instruction execution path and resume execution immediately after a replaced instruction.
Another example of conventional art of rewriting instructions in a program in order to dynamically change the structure of the program is disclosed in Japanese Patent Laying-Open (Kokai) No. Heisei 5-216649, entitled "System Program Dynamically Changing System" (hereinafter referred to as Literature 10). Recited in Literature 10 is a technique to have a means for receiving input of an additional instruction and registering the same, and an interruption instruction managing means and an interruption instruction executing means for executing the additional instruction, thereby modifying a system program without interrupting user's work processing. The technique recited in Literature 10, however, needs to manage an interruption instruction in addition to an original instruction execution path because an additional instruction is executed by interruption processing.
As described in the foregoing, conventional information processors have a drawback that a dynamic change of operation of an operating system is impossible which change is accompanied by a series of processing of setting a break point in the course of execution of the operating system in the normal operation mode, causing operation designated in advance at the point and then again resuming execution of the operating system.
Another shortcoming is that while an information processor is in operation, it is impossible to dynamically change operation of an operating system so that an arbitrary insertion procedure can be executed in the course of the execution of the operating system.
A further shortcoming is that because only one kind of instruction can be used at each procedure insertion position in an operating system, operation of detecting which procedure insertion position is executed is required to cost enormous processing time.